package com.vegetable.modules.entity.outbound;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.NullSerializer;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.vegetable.common.base.BaseEntity;
import com.vegetable.modules.entity.allocation.AllocationCollectionDetail;
import com.vegetable.modules.entity.allocation.vo.AllocationCollectionDetailWithSalesInfo;
import com.vegetable.modules.entity.finance.FinancialCollectionDetail;
import com.vegetable.modules.entity.inbound.OrderCost;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 销售出库单
 * </p>
 *
 * @author wangruijie
 * @since 2024-04-01
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="SalesOut对象", description="销售出库单")
public class SalesOut extends BaseEntity {

    @ApiModelProperty(value = "生产者ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long producerId;

    @ApiModelProperty(value = "销售订货id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long salesOrderId;

    @ApiModelProperty(value = "单据编号")
    private String docNo;
    @ApiModelProperty(value = "联系人电话")
    private String connectMobile;

    @ApiModelProperty(value = "批次号")
    private String lotNo;

    @ApiModelProperty(value = "订单时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private Date orderTime;

    @ApiModelProperty(value = "订单来源0订货发货，1新建")
    private Integer orderSource;

    @ApiModelProperty(value = "状态0未出库，1已出库 2部分出库")
    private Integer state;

    @ApiModelProperty(value = "状态0未对冲，1已对冲")
    private Integer hedgingState;

    @ApiModelProperty(value = "商户ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long customerId;

    @ApiModelProperty(value = "商户名称")
    private String customerName;

    @ApiModelProperty(value = "车辆ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long carId;

    @ApiModelProperty(value = "司机")
    private String carDriver;

    @ApiModelProperty(value = "车辆名称")
    private String carName;

    @ApiModelProperty(value = "销售金额")
    private BigDecimal money;

    @ApiModelProperty(value = "扣款金额")
    private BigDecimal deductionMoney;

    @ApiModelProperty(value = "已回款金额")
    private BigDecimal receivedMoney;

    @ApiModelProperty(value = "成本")
    private BigDecimal cost;

    @ApiModelProperty(value = "未对账金额")
    private BigDecimal verifyMonet;

    @ApiModelProperty(value = "收不回")
    @JsonSerialize(nullsUsing = NullSerializer.class)
    private BigDecimal noReturn;

    @ApiModelProperty(value = "待办补")
    @JsonSerialize(nullsUsing = NullSerializer.class)
    private BigDecimal agentDiscount;

    @ApiModelProperty(value = "提成")
    @JsonSerialize(nullsUsing = NullSerializer.class)
    private BigDecimal bonus;

    @ApiModelProperty(value = "数量")
    private Integer number;

    @ApiModelProperty(value = "重量")
    private BigDecimal weight;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "创建者ID")
    private Long createUserId;

    @ApiModelProperty(value = "创建时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private Date createTime;

    @ApiModelProperty(value = "商品明细")
    @TableField(exist = false)
    private List<SalesOutDetail> commodities;

    @ApiModelProperty(value = "带货明细")
    @TableField(exist = false)
    private List<SalesOutCarryOn> carryOnCommodities = new ArrayList<>();

    @ApiModelProperty(value = "其他费用")
    @TableField(exist = false)
    private List<OrderCost> costs;

    @ApiModelProperty(value = "车次")
    private String trainNum;

    @ApiModelProperty(value = "回款情况")
    @TableField(exist = false)
    private List<AllocationCollectionDetailWithSalesInfo> fcDetails;

    @ApiModelProperty(value = "异常情况")
    @TableField(exist = false)
    private List<String> errorList;


    @ApiModelProperty(value = "利润")
    @TableField(exist = false)
    private BigDecimal totalProfit;


    public BigDecimal getMoney() {
        return money != null ? money.setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
    }

    @ApiModelProperty(value = "台账标识 0寿光 1河北")
    private Integer regionId;

    @TableField(exist = false)
    @ApiModelProperty(value = "业务员")
    private String salesman;
    
    @TableField(exist = false)
    @ApiModelProperty(value = "业务员ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long salesmanId;
    
    @TableField(exist = false)
    @ApiModelProperty(value = "业务员姓名")
    private String salesmanName;
}